package cn.jishiyu11.xeqb.fragment

import android.annotation.SuppressLint
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.view.View
import cn.jishiyu11.xeqb.EntityClass.FragmengData.CardData
import cn.jishiyu11.xeqb.R
import cn.jishiyu11.xeqb.adapter.CardRecyclerAdapter
import cn.jishiyu11.xeqb.base.BaseFragment
import cn.jishiyu11.xeqb.utils.showShortToast
import com.umeng.analytics.MobclickAgent
import kotlinx.android.synthetic.main.frg_cardmanager_item.*

@SuppressLint("ValidFragment")
/**
 * Created by jsy_zj on 2018-03-05.
 *  卡片管理----卡片fragment
 */
class Card_Fragment constructor(var title:String, var type:Int):BaseFragment() {

    var cardList:MutableList<CardData>? = ArrayList()
    var cardRecyclerAdapter: CardRecyclerAdapter? = null

    override val layout: Int
        get() = R.layout.frg_cardmanager_item

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        card_manager_recycler.layoutManager = LinearLayoutManager(activity)
        getData()
        cardRecyclerAdapter = CardRecyclerAdapter(activity!!,cardList!!)
        card_manager_recycler.adapter = cardRecyclerAdapter

        card_manager_add.setOnClickListener {
            cardList?.add(CardData("这是新卡","https://www.baidu.com/img/bd_logo1.png","建行","2018.03.06"))
            setDataChanged()
        }

    }


    override fun initView() {

    }

    private fun setDataChanged(){

//        if (cardList!!.size > 0){
//            cardList?.clear()
//        }

//        cardList?.addAll(newList)
        cardRecyclerAdapter?.notifyDataSetChanged()

    }

    private fun getData(){
        //获取数据

        if (type == 0) {
            //信用卡
            cardList?.add(CardData("这是信用卡","https://www.baidu.com/img/bd_logo1.png","建行","2018.03.06"))
            cardList?.add(CardData("这是信用卡","https://www.baidu.com/img/bd_logo1.png","商行","2018.03.06"))
            cardList?.add(CardData("这是信用卡","https://www.baidu.com/img/bd_logo1.png","工行","2018.03.06"))
            //信用卡
            cardList?.add(CardData("这是信用卡","https://www.baidu.com/img/bd_logo1.png","建行","2018.03.06"))
            cardList?.add(CardData("这是信用卡","https://www.baidu.com/img/bd_logo1.png","商行","2018.03.06"))
            cardList?.add(CardData("这是信用卡","https://www.baidu.com/img/bd_logo1.png","工行","2018.03.06"))
            //信用卡
            cardList?.add(CardData("这是信用卡","https://www.baidu.com/img/bd_logo1.png","建行","2018.03.06"))
            cardList?.add(CardData("这是信用卡","https://www.baidu.com/img/bd_logo1.png","商行","2018.03.06"))
            cardList?.add(CardData("这是信用卡","https://www.baidu.com/img/bd_logo1.png","工行","2018.03.06"))
            //信用卡
            cardList?.add(CardData("这是信用卡","https://www.baidu.com/img/bd_logo1.png","建行","2018.03.06"))
            cardList?.add(CardData("这是信用卡","https://www.baidu.com/img/bd_logo1.png","商行","2018.03.06"))
            cardList?.add(CardData("这是信用卡","https://www.baidu.com/img/bd_logo1.png","工行","2018.03.06"))
            //信用卡
            cardList?.add(CardData("这是信用卡","https://www.baidu.com/img/bd_logo1.png","建行","2018.03.06"))
            cardList?.add(CardData("这是信用卡","https://www.baidu.com/img/bd_logo1.png","商行","2018.03.06"))
            cardList?.add(CardData("这是信用卡","https://www.baidu.com/img/bd_logo1.png","工行","2018.03.06"))
            //信用卡
            cardList?.add(CardData("这是信用卡","https://www.baidu.com/img/bd_logo1.png","建行","2018.03.06"))
            cardList?.add(CardData("这是信用卡","https://www.baidu.com/img/bd_logo1.png","商行","2018.03.06"))
            cardList?.add(CardData("这是信用卡","https://www.baidu.com/img/bd_logo1.png","工行","2018.03.06"))
        }else{
            //储蓄卡
            cardList?.add(CardData("这是银行卡","https://www.baidu.com/img/bd_logo1.png","建行","2018.03.06"))
            cardList?.add(CardData("这是银行卡","https://www.baidu.com/img/bd_logo1.png","商行","2018.03.06"))
            cardList?.add(CardData("这是银行卡","https://www.baidu.com/img/bd_logo1.png","工行","2018.03.06"))
        }



    }

    override fun onResume() {
        super.onResume()
        MobclickAgent.onPageStart("Card_Fragment")
    }

    override fun onPause() {
        super.onPause()
        MobclickAgent.onPageEnd("Card_Fragment")
    }



}